package com.spring.junitTest;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import com.spring.context.bean.SupBean;
import com.spring.test.CollectionInjection;
import com.spring.test.SayHello1;
import com.spring.test.TestInterfaceInjection;

public class Test {

    @org.junit.Test
    public void testBeanFactory() {

        BeanFactory fileSysBeanFactory = new FileSystemXmlApplicationContext(
                "F:\\huyuehan\\workspace\\springTest\\src\\com\\spring\\junitTest\\Test-context.xml");

        SayHello1 say = (SayHello1) fileSysBeanFactory
                .getBean("staticClassFactory");
        say.sayHello();

        BeanFactory classPathBeanFactory = new ClassPathXmlApplicationContext(
                "/com/spring/junitTest/Test-context.xml");

        SayHello1 say1 = (SayHello1) classPathBeanFactory
                .getBean("staticClassFactory");
        say1.sayHello();
    }

    @org.junit.Test
    public void testInterfaceInjection() {
        BeanFactory classPathBeanFactory = new ClassPathXmlApplicationContext(
                "/com/spring/junitTest/Test-context.xml");
        TestInterfaceInjection ij = classPathBeanFactory.getBean(
                "testInterfaceInjection", TestInterfaceInjection.class);

        ij.testMethod1();
    }

    @org.junit.Test
    public void testCollectionInjection() {
        BeanFactory classPathBeanFactory = new ClassPathXmlApplicationContext(
                "/com/spring/junitTest/Test-context.xml");
        CollectionInjection cj = classPathBeanFactory.getBean(
                "collectionInjection", CollectionInjection.class);

        cj.printList();

        cj.printSet();
        
        cj.pringMap();
    }

    @org.junit.Test
    public void testSpringIOCByParent() {
        BeanFactory classPathBeanFactory = new ClassPathXmlApplicationContext(
                "/com/spring/junitTest/Test-context.xml");
        SupBean b1 = classPathBeanFactory.getBean(
                "supBean", SupBean.class);

        System.out.println(b1.printTmp());
        
        SupBean b2 = classPathBeanFactory.getBean(
                "subBean1", SupBean.class);

        System.out.println(b2.printTmp());
        
        SupBean b3 = classPathBeanFactory.getBean(
                "subBean2", SupBean.class);

        System.out.println(b3.printTmp());
    }
}
